﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Uppg5
{
    public class WordCount
    {
        private HashTable<string, int> ht;

        public WordCount()
        {
            ht = new HashTable<string, int>(3571);
            string[] lines = System.IO.File.ReadAllLines("nils_holgersson.txt");
            foreach (string line in lines)
            {
                string[] words = line.Split();
                foreach(string word in words)
                {
                    Node<string, int> n = ht.Search(word);
                    if(n == null)
                    {
                        ht.Add(word, 1);
                    }
                    else
                    {
                        n.Value += 1;
                    }
                }
            }
        }

        public void Print()
        {
            ht.Print();
        }
    }
}
